Skip to content

Fix intellisense/completions for partial route parameter objects#880

Open
bakerkretzmar wants to merge 8 commits into2.xfrom
autocomplete-missing-required
Open

Fix intellisense/completions for partial route parameter objects#880
bakerkretzmar wants to merge 8 commits into2.xfrom
autocomplete-missing-required

Conversation

@bakerkretzmar
Copy link
Copy Markdown
Collaborator

This PR fixes #736, where route parameter names are not suggested/completed inside route() calls until all the route's required parameters are provided.

There are a few different pieces to this:

  • The core fix was just moving the config-only route(undefined, undefined, ...) overloaded type definition so that's it's defined last. This is enough to make intellisense find the earlier overloads and autocomplete params from them.
  • This stopped basic route name autocomplete from working, so to fix that I added an additional overload at the beginning to match just a route name and no other arguments.
  • When not in strict mode (strict and strictNullChecks missing from tsconfig.json or set to false), calling route(undefined, ...) does match the earlier overloads, and incorrectly appears to return a RouteUrl instead of a Router. Changing the name parameters to T & {} fixes this, preventing undefined from matching those params. This is kinda ugly but improves compatibility and I'm confident the tests we have prove it works fine.

This PR also finally adds real intellisense/autocompletion tests! We spin up a full TypeScript language service, pass it some fixture code, and assert against what completions it says it will generate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError when optional params omitted from array

1 participant